package com.moon.controller;

import com.moon.dto.TUser;
import com.moon.dto.TUserVo;
import com.moon.feign.UserFeign;
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserFeign userFeign;
    @RequestMapping("/login")
    @ResponseBody
    public Map<String, Object> login(@RequestBody TUser user) throws NoSuchAlgorithmException {
        return userFeign.login(user);
    }

    @RequestMapping("/register")
    @ResponseBody
    String register(TUserVo tUserVo) throws NoSuchAlgorithmException{
        return userFeign.register(tUserVo);
    }

    @RequestMapping("/findPasswordSendEmail")
    @ResponseBody
    String findPasswordSendEmail(TUserVo tUserVo) throws NoSuchAlgorithmException{
        return userFeign.findPasswordSendEmail(tUserVo);
    }

    @RequestMapping("/user/sendEmail")
    @ResponseBody
    String sendEmail(@RequestParam("to") String to, @RequestParam("subject") String subject, HttpServletRequest request) throws MessagingException{
        return userFeign.sendEmail(to,subject,request);
    }

}
